#!/usr/bin/env python
# encoding: utf-8

print "cwdate"

# built-in stuff
import unittest
import os
import sys
sys.path.append("../")
# home made stuff
from scriptgoodies import getTestingEnvironment
# stuff to test
from cwdate import *

class CwDateTest(unittest.TestCase):
	
	def setUp(self):
		self.env = getTestingEnvironment("cwdate.json")
		self.env["constants"]["platform"] = "mac"
	
	def testDay(self):
		self.env["prefs"]["cwDate_dateFormat"] = "%d"
		self.env["meta"]["actualPoorName"] = "CWDATE"
		self.env["meta"]["poorSuffix"] = ""
		self.env["static"]["cw_locale"] = ""
		result = main(self.env)[0][1]
		self.assert_(0 < int(result) < 32)
		self.assertEqual(result,time.strftime("%d"))
	
	def testLocale(self):
		self.env["prefs"]["cwDate_dateFormat"] = "%a"
		self.env["meta"]["actualPoorName"] = "CWDATE"
		self.env["meta"]["poorSuffix"] = ""
		self.env["static"]["cw_locale"] = "fr_FR.UTF-8"
		result = main(self.env)[0][1]
		self.assert_(result in ["Lun","Mar","Mer","Jeu","Ven","Sam","Dim"])
	
	def testHour(self):
		self.env["prefs"]["cwDate_hourFormat"] = "%H"
		self.env["meta"]["actualPoorName"] = "CWHOUR"
		self.env["meta"]["poorSuffix"] = "SHANGHAI"
		self.env["static"]["cw_locale"] = ""
		(hour,loc) = main(self.env)[0][1].split()
		self.assert_(0 <= int(hour) <= 23)
		self.assertEqual(loc,"(Asia/Shanghai)")
		#
		self.env["meta"]["poorSuffix"] = "BEIJING" # absent from the database
		hour = main(self.env)[0][1]
		self.assert_(0 <= int(hour) <= 23)
		#
		self.env["meta"]["poorSuffix"] = "SHANGHAI"
		self.env["constants"]["platform"] = "win"
		hour = main(self.env)[0][1]
		self.assert_(0 <= int(hour) <= 23)

if __name__ == '__main__':
	unittest.main()


